﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Interactivity;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;

namespace MvvmLight1
{
    public class MyHoverBehavior : Behavior<Border>
    {
        // Attached property mechanism !!!!
        public static bool GetHoverBehavior(DependencyObject obj)
        {
            return (bool)obj.GetValue(HoverBehaviorProperty);
        }

        public static void SetHoverBehavior(DependencyObject obj, bool value)
        {
            obj.SetValue(HoverBehaviorProperty, value);
        }

        // Using a DependencyProperty as the backing store for HoverBehavior.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HoverBehaviorProperty =
            DependencyProperty.RegisterAttached("HoverBehavior", typeof(bool), typeof(MyHoverBehavior),
            new UIPropertyMetadata(false, HoverBehaviorPropertyChanged));

        static void HoverBehaviorPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var border = sender as Border;

            border.MouseEnter += new System.Windows.Input.MouseEventHandler(border_MouseEnter);
            border.MouseLeave += new System.Windows.Input.MouseEventHandler(border_MouseLeave);
        }

        static void border_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var border = sender as Border;

            SkewTransform st = new SkewTransform(0, 0);
            border.RenderTransform = st;
            border.BorderBrush = Brushes.BurlyWood;
        }

        static void border_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var border = sender as Border;

            //SkewTransform st = new SkewTransform(1, -1);
            //border.RenderTransform = st;
            border.BorderBrush = Brushes.DarkRed;
        }

        //static void image_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        //{
        //    var image = sender as Image;
        //    image.Height = image.ActualHeight * 1.5;
        //    image.Width = image.ActualWidth * 1.5;
        //}

        //static void image_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        //{
        //    var image = sender as Image;
        //    image.Height = image.ActualHeight / 1.5;
        //    image.Width = image.ActualWidth / 1.5;
        //}
    }
}
